package com.ysqcould.web.controller.content;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.content.domain.InformationTag;
import com.ysqcould.content.service.IInformationTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资讯标签Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/content/tag")
public class InformationTagController extends BaseController
{
    @Autowired
    private IInformationTagService informationTagService;

    /**
     * 查询资讯标签列表
     */
    @PreAuthorize("@ss.hasPermi('content:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(InformationTag informationTag)
    {
        startPage();
        List<InformationTag> list = informationTagService.selectInformationTagList(informationTag);
        return getDataTable(list);
    }

    /**
     * 导出资讯标签列表
     */
    @PreAuthorize("@ss.hasPermi('content:tag:export')")
    @Log(title = "资讯标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InformationTag informationTag)
    {
        List<InformationTag> list = informationTagService.selectInformationTagList(informationTag);
        ExcelUtil<InformationTag> util = new ExcelUtil<InformationTag>(InformationTag.class);
        util.exportExcel(response, list, "资讯标签数据");
    }

    /**
     * 获取资讯标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('content:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(informationTagService.selectInformationTagById(id));
    }

    /**
     * 新增资讯标签
     */
    @PreAuthorize("@ss.hasPermi('content:tag:add')")
    @Log(title = "资讯标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InformationTag informationTag)
    {
        informationTag.setAsId(getUserId());
        return toAjax(informationTagService.insertInformationTag(informationTag));
    }

    /**
     * 修改资讯标签
     */
    @PreAuthorize("@ss.hasPermi('content:tag:edit')")
    @Log(title = "资讯标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InformationTag informationTag)
    {
        return toAjax(informationTagService.updateInformationTag(informationTag));
    }

    /**
     * 删除资讯标签
     */
    @PreAuthorize("@ss.hasPermi('content:tag:remove')")
    @Log(title = "资讯标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(informationTagService.deleteInformationTagByIds(ids));
    }
}
